package com.sf.osms.dep.dao.impl;

import java.util.List;

import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import com.sf.novatar.base.dao.BaseBeanDao;
import com.sf.osms.dep.dao.ICarCodeDao;
import com.sf.osms.dep.domain.CarCodeMap;

@Repository
public class CarCodeDao extends BaseBeanDao<Long,CarCodeMap> implements ICarCodeDao{

	@Override
	public List<CarCodeMap> findCarCodeMapById(Long agentId, String batchCode) {
		String sql = "select * from wbs_tt_car_code_map where agent_Id = ? and batch_Code = ?";
		Session session = this.getCurrentSession();
		SQLQuery query = session.createSQLQuery(sql);
		query.setLong(0, agentId);
		query.setString(1, batchCode);
		@SuppressWarnings("unchecked")
		List<CarCodeMap> list = query.addEntity(CarCodeMap.class).list();
		return list;
	}
	
	@Override
	public String queryCarCode(String agentName) {
		String sql = "select carno_type from wbs_tt_agent where  name = :agentName";
		SQLQuery query = getCurrentSession().createSQLQuery(sql);
	    query.setString("agentName", agentName);
	    List<String> list = query.list();
	    if(list.size()<1){
	    	return null;
	    }
		return list.get(0);
	}

}
